import sys
g_board = []
g_size = 8
g_rows = []
g_diagonals = []

def print_board():
    for row in g_board:
        print(row)

def init_board():
    for i in range(0,g_size):
        g_board.append([0] * g_size)

def is_attacked( x, y ):
    return x in g_rows or (x,y) in g_diagonals

def is_in_board(x,y):
    return 0 <= x < g_size and 0 <= y < 8

def add_diagonals(x, y, add):
    if add:
        g_diagonals.append((x,y))
    else:
        g_diagonals.remove((x,y))
    dx = x
    dy = y
    while is_in_board(dx-1, dy-1):
        dx -= 1
        dy -= 1
        if add:
            g_diagonals.append((dx,dy))
        else:
            g_diagonals.remove((dx,dy))

    dx = x
    dy = y
    while is_in_board(dx+1, dy+1):
        dx += 1
        dy += 1
        if add:
            g_diagonals.append((dx,dy))
        else:
            g_diagonals.remove((dx,dy))

    dx = x
    dy = y
    while is_in_board(dx-1, dy+1):
        dx -= 1
        dy += 1
        if add:
            g_diagonals.append((dx,dy))
        else:
            g_diagonals.remove((dx,dy))

    dx = x
    dy = y
    while is_in_board(dx+1, dy-1):
        dx += 1
        dy -= 1
        if add:
            g_diagonals.append((dx,dy))
        else:
            g_diagonals.remove((dx,dy))



def solve( y ):
    if y >= g_size:
        print_board()
        sys.exit(1)

    for x in range(0,g_size):
        if not is_attacked( x, y ):
            g_board[x][y] = 1
            g_rows.append(x)
            add_diagonals(x,y, True)
            solve(y+1)
            g_board[x][y] = 0
            g_rows.remove(x)
            add_diagonals(x,y, False)



init_board()
solve(0)
